@extends('layouts.app')
@section('content')

  <div class="row">
        <div class="small-3 columns">
          <input type="text" id="filter" placeholder="search">
        </div>
        <div class="small-5 columns">
<!--<a href="{{$table}}/create" data-reveal-id="mymodal" data-reveal-ajax="true" class='button small'>add</a>-->
<a href="{{$table}}/create" class='button small'>add</a>

        </div>
  </div>

<table class="data-table" data-filter='#filter'>
  <thead>
    <tr>
      @foreach($columns as $label=>$arr)
      <th>{{$label}}</th>
      @endforeach
      </tr>
    </thead>
  <tbody>
    @foreach($objects as $obj)
    <tr class='data-table-row' id='{{ $obj->id }}'>
<?php
foreach ($columns as $label=>$arr) {
    if (is_callable ($arr['field'])) {
        $val = $arr['field']($obj);
    } else if (isset ($obj->$arr['field'])){
        $val = $obj->$arr['field'];
    } else {
        $val = '&nbsp;';
    }
    echo "<td>{$val}</td>\n";
}
?>
      </tr>
    @endforeach
    </tbody>
</table>

<div id='mymodal' class='reveal-modal' data-reveal></div>

<script type="text/javascript">
$(function () {
    $('.data-table').footable();

    $('.data-table-row').click(function() {
      $('#mymodal').foundation('reveal', 'open', {
        url: '/{{$table}}/' + $(this).attr('id')
      });
    });
});
</script>

@stop